<?php

namespace app\api\controller\user;

use app\api\validate\user\CreatorValidate;
use app\common\controller\Frontend;
use app\logic\user\UserLogic;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

class Creator extends Frontend
{
    protected array $noNeedLogin = [];

    protected array $noNeedPermission = [];

    public function initialize(): void
    {
        parent::initialize();

    }

    /**
     * 达人申请
     */
    public function apply()
    {
        $params = $this->request->param(['images', 'video', 'document_type', "document_images", "motto"]);

        // 创建验证器实例并验证数据
        $validator = new CreatorValidate();
        $result = $validator->check($params);
        // 验证结果判断
        if ($result !== true) {
            // 如果验证失败，返回错误信息
            $this->error($validator->getError());
        }

        try {
            $result = UserLogic::getInstance()->creatorApply($this->auth->id, $params);
        } catch (\RuntimeException $e) {
            $this->error($e->getMessage());
        } catch (\Throwable $e) {
            $this->error(__('server error'));
        }
        // 验证通过，执行后续操作
        $this->success(__('success'), $result);
    }
}